﻿using B.S.DataBase.MyProject.ErrorCode;
using B.S.Traceability.Domain;
using B.S.Traceability.Infrastructure.Interface;
using B.S.Traceability.Read.API.Applicantion.Command.PhoneCommand;
using MediatR;

namespace B.S.Traceability.Read.API.Applicantion.CommandHandler.PhoneCommandHandler
{
    public class QueryPhoneCommandHandler : IRequestHandler<QueryPhoneCommand, APIResult<List<SU_PhoneInfo>>>
    {
        private readonly IBaseRepository<SU_PhoneInfo> phoneRep;
        public QueryPhoneCommandHandler(IBaseRepository<SU_PhoneInfo> phoneRep)
        {
            this.phoneRep = phoneRep;
        }
        public Task<APIResult<List<SU_PhoneInfo>>> Handle(QueryPhoneCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<SU_PhoneInfo>> result=new APIResult<List<SU_PhoneInfo>>();
            var list = phoneRep.GetAll().Result.Where(x => x.PhoneType == request.PhoneType && x.ProductionCode == request.ProductionCode);
            result.Code = APIEnum.查询成功;
            result.Msg = APIEnum.查询成功.ToString();
            result.data=list.ToList();
            return Task.FromResult(result);
        }
    }
}
